﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

public class NewProductByGroupProductViewer
{
    static CProductFacade facade = new CProductFacade();
    public static string View(int numberOfRecord, int groupId, int brandId, ref string listProductId)
    {
        StringBuilder strLargeImage = new StringBuilder();
        StringBuilder str = new StringBuilder();
        IList<Product> list = facade.List(1, numberOfRecord, groupId, brandId);
        for (int i = 0; i < list.Count; i++)
        {
            Product item = list[i];
            strLargeImage.Append(item.ProductId.ToString() + "|");
            //if (String.IsNullOrEmpty(item.ProductImage))
            //{
            //    item.ProductImage = _defaultImg;
            //}
            //else
            //{
            //    item.ProductImage = "../Admin/Upload/Image/Product/" + item.ProductImage;
            //}
            if (item.ProductDescription.Length > 85)
            {
                item.ProductDescription = item.ProductDescription.Substring(0, 85);
            }
            if (i % 2 != 0)
            {
                str.AppendFormat(_formatLeft, item.ProductImage, item.ProductName, item.ProductDescription, Formatter.PriceVietNamese(item.ProductPrice), item.ProductId);
            }
            else
            {
                str.AppendFormat(_formatRight, item.ProductImage, item.ProductName, item.ProductDescription, Formatter.PriceVietNamese(item.ProductPrice), item.ProductId);
            }
        }
        listProductId = strLargeImage.ToString();
        return str.ToString();
    }
    #region _format

    static string _defaultImg = "../img/layout/blankproduct.gif";
    static string _formatRight = "<div class='tooltip-content' id='largeImage{4}'><img src='{0}' height='350' /></div>" +
    "<div class='content'>" +
        "<div class='item'>" +
            "<div class='img'>" +
                "<img src='{0}' width='' height='123' />" +
            "</div>" +
            "<div class='info'>" +
                "<div class='title'>" +
                    "<a href='ProductDetail.aspx?pi={4}'>{1}</a>" + "</div>" +
                "<div class='newrow desc'>" +
                    "<label>{2}...</label>" +
                "</div>" +
                "<div class='newrow price'>" +
                    "<label>{3} VNĐ</label>" + "</div>" +
                "<div class='newrow add'>" +
                    "<a href='javascript:Five.Cart.Add({4})'><img src='../img/layout/addcart.gif' /></a>" + "</div>" +
            "</div>" +
        "</div>" +
    "</div>";

    static string _formatLeft = "<div class='tooltip-content' id='largeImage{4}'><img src='{0}' height='350' /></div>" +
    "<div class='content left'>" +
        "<div class='item'>" +
            "<div class='img'>" +
                "<img src='{0}' width='' height='123' />" +
            "</div>" +
            "<div class='info'>" +
                "<div class='title'>" +
                    "<a href='ProductDetail.aspx?pi={4}'>{1}</a>" + "</div>" +
                "<div class='newrow desc'>" +
                    "<label>{2}...</label>" +
                "</div>" +
                "<div class='newrow price'>" +
                    "<label>{3} VNĐ</label>" + "</div>" +
                "<div class='newrow add'>" +
                    "<a href='javascript:Five.Cart.Add({4})'><img src='../img/layout/addcart.gif' /></a>" + "</div>" +
            "</div>" +
        "</div>" +
    "</div>";
    #endregion
}